﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LB.Server.DAL.DomainEntitites
{
    public class Part
    {
        /// <summary>
        /// Last n versions of current part
        /// </summary>
        public List<TextContent> Contents { get; set; }

        /// <summary>
        /// Part before current
        /// </summary>
        public Part ParentPart { get; set; }

        /// <summary>
        /// Id of the current part
        /// </summary>
        public int PartId { get; set; }

        /// <summary>
        /// Last version of the content
        /// </summary>
        public TextContent Content
        {
            get
            {
                if (Contents != null && Contents.Count > 0)
                    return Contents.Where(c => c.Version == Contents.Max(a => a.Version)).FirstOrDefault();
                return null;
            }
        }

        /// <summary>
        /// try to add new version of content.
        /// </summary>
        /// <returns>true if new content was added successfully, false if item with such content already exist</returns>
        public bool UpdateContent(string newContent)
        {
            throw new NotImplementedException("Part.UpdateContent");
        }
    }
}